import requests
import os


def upload_files(base_path, start=1, end=9):
    url = "http://127.0.0.1:9876/api/training/file/uploadFile"
    headers = {
        'Auth': 'Bearer f6baa640-f9e0-466f-b876-bd60196db4e6',
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
    }

    for i in range(start, end + 1):
        filename = f'角色B-{i}.MP3'
        file_path = os.path.join(base_path, filename)

        try:
            files = [
                ('file', (filename, open(file_path, 'rb'), 'audio/mpeg'))
            ]
            response = requests.post(url, headers=headers, data={}, files=files)
            print(f"Uploading {filename}: {response.text}")

        except Exception as e:
            print(f"Error uploading {filename}: {str(e)}")

        finally:
            # Close the file handle
            if 'files' in locals():
                files[0][1][1].close()


# Example usage
base_path = r'C:\Users\metype\Desktop\角色分离\角色B'
upload_files(base_path)





